<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Payment extends CI_Controller {
	
	private $tab = 'system';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	function payonline(){
		$this->load->model('Payment_model', 'payment');
		
		$paymentlist = $this->payment->get_list();
		
		$vdata['list'] = $paymentlist;
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'payparameter';
		
		$vdata['payment_fstatus'] = array(0=>'是',1=>'否');
		$this->load->view('/sys_admin/system/payonline_list', $vdata);
	}
	
	
	function pay_synchronize(){
		$this->load->model('Payment_model', 'payment');
		
		$id = $this->input->post("id");
		$info = $this->payment->get_one(array('id'=>$id));
		$tmp = unserialize($info['config']);
		$info['member_id'] = $tmp['member_id'];
		$info['privateKey'] = $tmp['PrivateKey'];
		$ret = array('msg'=>$info);
		echo json_encode($ret);
		exit; 
	}
	
	function addparameter(){
		$this->load->model('Payment_model', 'payment');
		$act = $this->input->post('act');
		$this->load->model('log_model');
		
		if(isset($act) && $act){
			$id = 	$this->input->post('id');
			$info = $this->payment->get_one(array('id'=>$id));
			if($act == 'edit'){
				$config_arr = array(
								'member_id'=>$this->input->post('member_id'),
								'PrivateKey'=>$this->input->post('privateKey'),
							);
				$config = serialize($config_arr);
			
				$edata = array(
					'config'        =>$config,
					'payment_order'        => $this->input->post('payment_order'),
					'description'        => $this->input->post('description'),
					'fstatus'        => $this->input->post('fstatus')
				
				);
				$res = $this->payment->update($id,$edata);
				
				if($res>0){
					$this->log_model->add_log('[编辑][支付接口管理]->['.$info['name'].']');
					$ret = array('msg'=>'操作成功');
				}else{
					$ret = array('msg'=>'操作失败');
				}
				echo json_encode($ret);
				exit; 
			}else if($act =='delete'){
				$ddata = array('fstatus'=>1);
				$res = $this->payment->update($id,$ddata);
				if($res>0){
					$this->log_model->add_log('[删除][支付接口管理]->['.$info['name'].']');
					$ret = array('msg'=>'操作成功');
				}else{
					$ret = array('msg'=>'操作失败');
				}
				echo json_encode($ret);
				exit; 
			}		
	   		
		}
 		
	}
	
	
	function pay(){
		$this->load->model('Payment_model', 'payment');
		$response_html='';
		$nid = $this->input->post('nid');
		$where = array('nid' =>$nid);
		$payinfo = $this->payment->get_one($where);
		
		if($payinfo){
			$payment = unserialize($payinfo['config']);
			$payinfo['member_id'] = $payment['member_id'];
			$payinfo['PrivateKey'] = $payment['PrivateKey'];
		}else{
			$payinfo['nid'] = $nid;
			$payinfo['name'] = $this->input->post('name');
		}
		
		$view_data['payinfo'] = $payinfo;
		
		$response_html = $this->load->view("/sys_admin/payment/pay.php",$view_data,true);
		echo $response_html;
		exit;
	}
	
	function msgonline(){
		
		$this->load->model('Payment_model', 'payment');
		
		$vdata['email'] = $this->payment->get_msg_one(array('type' =>1));
		$vdata['msg'] = $this->payment->get_msg_one(array('type' =>2));
		
		$vdata['tab'] = 'information';
		$vdata['sub'] = $this->sub;
		$this->load->view('/sys_admin/msgonline_list', $vdata);
	}
	
	function savemsgonline(){		
		$type = $this->input->post('type');
		
		$data = array(
				'type'  => $type,
				'username' 		 => $this->input->post('msg_username'),
				'pwd'        => $this->input->post('msg_pswd')
		);
		
		
		$smtp_host = $this->input->post('msg_smtp_host');
		if(isset($smtp_host) && $smtp_host !=''){
			$data['smtp_host'] = $smtp_host;
		}
		
		$id = $this->input->post('msg_id');
		
		$this->load->model('Payment_model', 'payment');
		
		$admin = $this->session->userdata('admin_user');
		if(isset($admin['type_id']) && $admin['type_id'] ==1){
			if($id>0){				
				$this->payment->update_msg($id,$data);
			}else{
				$id = $this->payment->add_msg($data);
			}	
			
			$this->create_file($_POST);
			$ret['msg'] = '操作成功';
			echo json_encode($ret);
			exit; 	
		}else{
			$ret['msg'] = '对不起，权限不足';
			echo json_encode($ret);
			exit;
		}
			
		
		
			
	}
	
	/**
	 * 创建文件
	 * @param $cont
	 */
	 //*
	private function create_file($cont){
		
		$this->load->model('Payment_model', 'payment');
		$email= $this->payment->get_msg_one(array('type' =>1));
		$msg = $this->payment->get_msg_one(array('type' =>2));
		$qq = $this->payment->get_msg_one(array('type' =>3));
		$sina = $this->payment->get_msg_one(array('type' =>4));
		
		
		$stmp_username = $email['username'];
		
		$smtp_pswd = $email['pwd'];
		$smtp_host = $email['smtp_host'];
		
		$msg_username = $msg['username'];
		$msg_pswd = $msg['pwd'];
		
		$qq_username = $qq['username'];
		$qq_pswd = $qq['pwd'];
		$qq_smtp_host = $qq['smtp_host'];
		
		$sina_username = $sina['username'];
		$sina_pswd = $sina['pwd'];
		$sina_smtp_host = $sina['smtp_host'];
		
		
		$data ="<?php".PHP_EOL
		."define('EMAIL_USER_NAME', 				'$stmp_username');//SMTP用户名".PHP_EOL
		."define('EMAIL_PASSWD', 		'$smtp_pswd');//SMTP密码".PHP_EOL
		."define('EMAIL_HOST_STMP', 		'$smtp_host');//SMTP服务器".PHP_EOL
		."define('PHONE_USER_NAME', 			'$msg_username');//短信用户名".PHP_EOL
		."define('PHONE_PASSWD', 				'$msg_pswd');//短信密码".PHP_EOL
		."define('APP_ID', 			'$qq_username');//QQ APP_ID".PHP_EOL
		."define('APP_KEY', 				'$qq_pswd');//QQ APP_KEY".PHP_EOL
		."define('APP_CALLBACK_URL', 				'$qq_smtp_host');//QQ APP_CALLBACK_URL".PHP_EOL
		."define('WB_AKEY', 			'$sina_username');//SINA WB_AKEY".PHP_EOL
		."define('WB_SKEY', 				'$sina_pswd');//SINA WB_SKEY".PHP_EOL
		."define('WB_CALLBACK_URL', 				'$sina_smtp_host');//SINA WB_CALLBACK_URL".PHP_EOL;
		
		$this->load->helper('file');
		if(!write_file('./application/config/constants_msgonline.php', $data,'w+')){
			error_log("Unable to write the file",3,"/var/www/html/test.yunchsoft.com/payment.log");
		}else{
			write_file('./application/config/constants_msgonline.php', $data,'w+');
		}
	}
	
	
	function loginonline(){
		$this->load->model('Payment_model', 'payment');
		
		$vdata['qq'] = $this->payment->get_msg_one(array('type' =>3));
		$vdata['sina'] = $this->payment->get_msg_one(array('type' =>4));
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'login';
		
		
		$this->load->view('/sys_admin/loginonline_list', $vdata);
	}
	

=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Payment extends CI_Controller {
    
	private $tab = 'system';
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
	}
	
	function payonline(){
		$this->load->model('Payment_model', 'payment');
		
		$paymentlist = $this->payment->get_list();
		
		$vdata['list'] = $paymentlist;
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'payparameter';
		
		$vdata['payment_fstatus'] = array(0=>'是',1=>'否');
		$this->load->view('/sys_admin/system/payonline_list', $vdata);
	}
	
	
	function pay_synchronize(){
		$this->load->model('Payment_model', 'payment');
		
		$id = $this->input->post("id");
		$info = $this->payment->get_one(array('id'=>$id));
		$tmp = unserialize($info['config']);
		$info['member_id'] = $tmp['member_id'];
		$info['privateKey'] = $tmp['PrivateKey'];
		$ret = array('msg'=>$info);
		echo json_encode($ret);
		exit; 
	}
	
	function addparameter(){
		$this->load->model('Payment_model', 'payment');
		$act = $this->input->post('act');
		$this->load->model('log_model');
		
		if(isset($act) && $act){
			$id = 	$this->input->post('id');
			$info = $this->payment->get_one(array('id'=>$id));
			if($act == 'edit'){
				$config_arr = array(
								'member_id'=>$this->input->post('member_id'),
								'PrivateKey'=>$this->input->post('privateKey'),
							);
				$config = serialize($config_arr);
			
				$edata = array(
					'config'        =>$config,
					'payment_order'        => $this->input->post('payment_order'),
					'description'        => $this->input->post('description'),
					'fstatus'        => $this->input->post('fstatus')
				
				);
				$res = $this->payment->update($id,$edata);
				
				if($res>0){
					$this->log_model->add_log('[编辑][支付接口管理]->['.$info['name'].']');
					$ret = array('msg'=>'操作成功');
				}else{
					$ret = array('msg'=>'操作失败');
				}
				echo json_encode($ret);
				exit; 
			}else if($act =='delete'){
				$ddata = array('fstatus'=>1);
				$res = $this->payment->update($id,$ddata);
				if($res>0){
					$this->log_model->add_log('[删除][支付接口管理]->['.$info['name'].']');
					$ret = array('msg'=>'操作成功');
				}else{
					$ret = array('msg'=>'操作失败');
				}
				echo json_encode($ret);
				exit; 
			}		
	   		
		}
 		
	}
	
	
	function pay(){
		$this->load->model('Payment_model', 'payment');
		$response_html='';
		$nid = $this->input->post('nid');
		$where = array('nid' =>$nid);
		$payinfo = $this->payment->get_one($where);
		
		if($payinfo){
			$payment = unserialize($payinfo['config']);
			$payinfo['member_id'] = $payment['member_id'];
			$payinfo['PrivateKey'] = $payment['PrivateKey'];
		}else{
			$payinfo['nid'] = $nid;
			$payinfo['name'] = $this->input->post('name');
		}
		
		$view_data['payinfo'] = $payinfo;
		
		$response_html = $this->load->view("/sys_admin/payment/pay.php",$view_data,true);
		echo $response_html;
		exit;
	}
	
	function msgonline(){
		
		$this->load->model('Payment_model', 'payment');
		
		$vdata['email'] = $this->payment->get_msg_one(array('type' =>1));
		$vdata['msg'] = $this->payment->get_msg_one(array('type' =>2));
		
		$vdata['tab'] = 'information';
		$vdata['sub'] = $this->sub;
		$this->load->view('/sys_admin/msgonline_list', $vdata);
	}
	
	function savemsgonline(){		
		$type = $this->input->post('type');
		
		$data = array(
				'type'  => $type,
				'username' 		 => $this->input->post('msg_username'),
				'pwd'        => $this->input->post('msg_pswd')
		);
		
		
		$smtp_host = $this->input->post('msg_smtp_host');
		if(isset($smtp_host) && $smtp_host !=''){
			$data['smtp_host'] = $smtp_host;
		}
		
		$id = $this->input->post('msg_id');
		
		$this->load->model('Payment_model', 'payment');
		
		$admin = $this->session->userdata('admin_user');
		if(isset($admin['type_id']) && $admin['type_id'] ==1){
			if($id>0){				
				$this->payment->update_msg($id,$data);
			}else{
				$id = $this->payment->add_msg($data);
			}	
			
			$this->create_file($_POST);
			$ret['msg'] = '操作成功';
			echo json_encode($ret);
			exit; 	
		}else{
			$ret['msg'] = '对不起，权限不足';
			echo json_encode($ret);
			exit;
		}
			
		
		
			
	}
	
	/**
	 * 创建文件
	 * @param $cont
	 */
	 //*
	private function create_file($cont){
		
		$this->load->model('Payment_model', 'payment');
		$email= $this->payment->get_msg_one(array('type' =>1));
		$msg = $this->payment->get_msg_one(array('type' =>2));
		$qq = $this->payment->get_msg_one(array('type' =>3));
		$sina = $this->payment->get_msg_one(array('type' =>4));
		
		
		$stmp_username = $email['username'];
		
		$smtp_pswd = $email['pwd'];
		$smtp_host = $email['smtp_host'];
		
		$msg_username = $msg['username'];
		$msg_pswd = $msg['pwd'];
		
		$qq_username = $qq['username'];
		$qq_pswd = $qq['pwd'];
		$qq_smtp_host = $qq['smtp_host'];
		
		$sina_username = $sina['username'];
		$sina_pswd = $sina['pwd'];
		$sina_smtp_host = $sina['smtp_host'];
		
		
		$data ="<?php".PHP_EOL
		."define('EMAIL_USER_NAME', 				'$stmp_username');//SMTP用户名".PHP_EOL
		."define('EMAIL_PASSWD', 		'$smtp_pswd');//SMTP密码".PHP_EOL
		."define('EMAIL_HOST_STMP', 		'$smtp_host');//SMTP服务器".PHP_EOL
		."define('PHONE_USER_NAME', 			'$msg_username');//短信用户名".PHP_EOL
		."define('PHONE_PASSWD', 				'$msg_pswd');//短信密码".PHP_EOL
		."define('APP_ID', 			'$qq_username');//QQ APP_ID".PHP_EOL
		."define('APP_KEY', 				'$qq_pswd');//QQ APP_KEY".PHP_EOL
		."define('APP_CALLBACK_URL', 				'$qq_smtp_host');//QQ APP_CALLBACK_URL".PHP_EOL
		."define('WB_AKEY', 			'$sina_username');//SINA WB_AKEY".PHP_EOL
		."define('WB_SKEY', 				'$sina_pswd');//SINA WB_SKEY".PHP_EOL
		."define('WB_CALLBACK_URL', 				'$sina_smtp_host');//SINA WB_CALLBACK_URL".PHP_EOL;
		
		$this->load->helper('file');
		if(!write_file('./application/config/constants_msgonline.php', $data,'w+')){
			error_log("Unable to write the file",3,"/var/www/html/test.yunchsoft.com/payment.log");
		}else{
			write_file('./application/config/constants_msgonline.php', $data,'w+');
		}
	}
	
	
	function loginonline(){
		$this->load->model('Payment_model', 'payment');
		
		$vdata['qq'] = $this->payment->get_msg_one(array('type' =>3));
		$vdata['sina'] = $this->payment->get_msg_one(array('type' =>4));
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'login';
		
		
		$this->load->view('/sys_admin/loginonline_list', $vdata);
	}
	

>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
}